package com.briup.day13;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

/**
 * //3个老师.具有排序规则 由小到大  自定义场景 （匿名内部类方式创建比较器）
 * @author lining
 * @date 2024/1/24 15:13
 */
public class Test9 {
    public static void main(String[] args) {
        //1.匿名内部类创建比较器对象 () -> {}
        //2.在创建set集合放在构造器中使用
        /*Set<Teacher> teachers = new TreeSet<>(new Comparator<Teacher>() {
            public int compare(Teacher o1, Teacher o2) {
                // o1  新  o2 旧
                //  1      2
                return o1.getId() - o2.getId();
            }
        });*/
        Set<Teacher> teachers = new TreeSet<>((o1,o2) -> o1.getId() - o2.getId());
        teachers.add(new Teacher(1,"jack"));
        teachers.add(new Teacher(1,"jack"));
        teachers.add(new Teacher(3,"jack"));
        System.out.println(teachers);//
    }
}
